<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>04_自定义构造函数模式</title>
  </head>

  <body>
    <!--
    方式四: 自定义构造函数模式
      * 套路: 自定义构造函数, 通过new创建对象
      * 适用场景: 需要创建多个类型确定的对象
      * 问题: 每个对象都有相同的数据, 浪费内存
    -->
    <script type="text/javascript">
      /*  
        构造函数 的 作用
          1. 简化 创建对象的 过程
          2. 区分不同类型的对象
      */
      function Person(name, age, gender, height, weigth) {
        this.name = name
        this.age = age
        this.gender = gender
        this.height = height
        this.weight = weigth
        this.sayHi = function () {}
      }


      function Dog(name, age, gender, height, weigth) {
        this.name = name
        this.age = age
        this.gender = gender
        this.height = height
        this.weight = weigth
        this.sayHi = function () {}
      }

      let p1 = new Person('狗蛋', 16, '男', 160, '80kg')
      let d1 = new Dog('旺财', 3, '公', 100, '30kg')
      console.log(p1);
      console.log(d1);
    </script>
  </body>

</html>